package com.egao.common.module.recommendation.controller;

import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.recommendation.entity.GraduateEmploymentCertification;
import com.egao.common.module.recommendation.entity.vo.RecommendationAuditParam;
import com.egao.common.module.recommendation.entity.vo.RecommendationListVo;
import com.egao.common.module.recommendation.service.IGraduateEmploymentCertificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *  控制器
 *
 * @author shu
 */
@Api(tags = "管理")
@RestController
@RequestMapping("${api}")
public class GraduateEmploymentCertificationController extends BaseController {

    private IGraduateEmploymentCertificationService graduateEmploymentCertificationService;

    @Autowired
    public GraduateEmploymentCertificationController(IGraduateEmploymentCertificationService graduateEmploymentCertificationService){
        this.graduateEmploymentCertificationService = graduateEmploymentCertificationService;
    }

    @PreAuthorize("hasAuthority('graEmplCert:list')")
    @ApiOperation("查询列表")
    @GetMapping("/graEmplCert/list")
    public PageResult<RecommendationListVo> list(HttpServletRequest request) {
        PageParam<GraduateEmploymentCertification> pageParam = new PageParam<>(request);
        return graduateEmploymentCertificationService.list(pageParam);
    }

    @PreAuthorize("hasAuthority('graEmplCert:read')")
    @ApiOperation("查询单个")
    @GetMapping("/graEmplCert/read/{id}")
    public JsonResult read(@PathVariable("id") Integer id) {
        return graduateEmploymentCertificationService.read(id);
    }

    @PreAuthorize("hasAuthority('graEmplCert:my')")
    @ApiOperation("本人查询")
    @GetMapping("/graEmplCert/my")
    public JsonResult read() {
        return graduateEmploymentCertificationService.read();
    }

    @PreAuthorize("hasAuthority('graEmplCert:add')")
    @ApiOperation("添加")
    @PostMapping("/graEmplCert/add")
    public JsonResult add(@RequestBody GraduateEmploymentCertification model) {
        return graduateEmploymentCertificationService.add(model);
    }

    @PreAuthorize("hasAuthority('graEmplCert:update')")
    @ApiOperation("保存")
    @PostMapping("/graEmplCert/update")
    public JsonResult update(@RequestBody GraduateEmploymentCertification model) {
        return graduateEmploymentCertificationService.update(model);
    }

    @PreAuthorize("hasAuthority('graEmplCert:delete')")
    @ApiOperation("删除")
    @GetMapping("/graEmplCert/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Integer[] ids) {
        return graduateEmploymentCertificationService.delete(ids);
    }

    @PreAuthorize("hasAuthority('graEmplCert:submit')")
    @ApiOperation("提交")
    @GetMapping("/graEmplCert/submit/{id}")
    public JsonResult submit(@PathVariable("id") Integer id){
        return graduateEmploymentCertificationService.submit(id);
    }

    @PreAuthorize("hasAuthority('graEmplCert:audit')")
    @ApiOperation("审核")
    @PostMapping("/graEmplCert/audit")
    public JsonResult audit(@RequestBody RecommendationAuditParam param) {
        return graduateEmploymentCertificationService.audit(param);
    }

    @PreAuthorize("hasAuthority('graEmplCert:export')")
    @ApiOperation("导出")
    @GetMapping("/graEmplCert/export/{id}")
    public JsonResult export(@PathVariable("id") Integer id, HttpServletResponse response) throws IOException {
        return graduateEmploymentCertificationService.export(id,response);
    }

}